package com.luo.demo.ks.devops.controller;

import com.luo.demo.ks.devops.dto.ParamArrayDto;
import com.luo.demo.ks.devops.dto.ParamListDto;
import com.luo.demo.ks.devops.utils.JsonUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * REST服务 - Controller
 *
 * @author luohq
 * @date 2023-03-30
 */
@RestController
@RequestMapping("/api/v1/tests")
@Slf4j
public class RestParamsTestController {

    @GetMapping("/list")
    public String getByList(@RequestParam(required = true) List<String> ids) {
        String paramJson = JsonUtils.toJson(ids);
        log.info("getByList: {}", paramJson);
        return paramJson;
    }
    @GetMapping("/array")
    public String getByArray(@RequestParam(required = true) String[] ids) {
        String paramJson = JsonUtils.toJson(ids);
        log.info("getByArray: {}", paramJson);
        return paramJson;
    }

    @PostMapping("/list")
    public String postByList(ParamListDto dto) {
        String paramJson = JsonUtils.toJson(dto);
        log.info("postByList: {}", paramJson);
        return paramJson;
    }

    @PostMapping("/array")
    public String postByArray(ParamArrayDto dto) {
        String paramJson = JsonUtils.toJson(dto);
        log.info("postByArray: {}", paramJson);
        return paramJson;
    }

    @DeleteMapping("/list/{ids}")
    public String deleteByList(@PathVariable(required = true) List<String> ids) {
        String paramJson = JsonUtils.toJson(ids);
        log.info("deleteByList: {}", paramJson);
        return paramJson;
    }
    @DeleteMapping("/array/{ids}")
    public String deleteByArray(@PathVariable(required = true) String[] ids) {
        String paramJson = JsonUtils.toJson(ids);
        log.info("deleteByArray: {}", paramJson);
        return paramJson;
    }
}
